package main

import (
	"fmt"
)

func main() {
	// 1. 求数组[1,3,4,7,8]所有元素的和
	arr := [...]int{1, 3, 4, 7, 8}
	var sum = 0
	for _, v := range arr {
		sum += v
	}
	fmt.Printf("sum: %v\n", sum)

	// 2.从数组[1,3,5,7,8]中找出和为8的两个元素的下标分别为(0,3)和(1,2)
	arr2 := [...]int{1, 3, 5, 7, 8}
	for i1, v1 := range arr2 {
		for j := 0; j < len(arr2)-i1; j++ {
			if v1+arr2[i1+j] == 8 {
				fmt.Printf("(%d,%d)", i1, i1+j)
			}
		}
	}
}
